package com.github.pig.admin.controller.repair;

import com.baomidou.mybatisplus.plugins.Page;
import com.github.pig.admin.model.entity.PaymentRecord;
import com.github.pig.admin.service.pay.IPaymentRecordService;
import com.github.pig.admin.service.user.SysUserService;
import com.github.pig.common.constant.CommonConstant;
import com.github.pig.common.util.R;
import com.github.pig.common.web.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * <p>
 * 缴费记录表 前端控制器
 * </p>
 *
 * @author xiaosa
 * @since 2018-07-23
 */
@RestController
@RequestMapping("/paymentRecord")
public class PaymentRecordController extends BaseController {
    @Autowired private IPaymentRecordService paymentRecordService;
    @Autowired
    private SysUserService sysUserService;

    /**
    * 通过ID查询
    *
    * @param id ID
    * @return PaymentRecord
    */
    @GetMapping("/{id}")
    public PaymentRecord get(@PathVariable String id) {
        return paymentRecordService.selectById(id);
    }


    /**
    * 分页查询信息
    *
    * @param params 分页对象
    * @return 分页对象
    */
    @RequestMapping("/page")
    public Page page(@RequestParam Map<String, Object> params) {
        Page<PaymentRecord> page = new Page<>(Integer.parseInt(params.get("page")==null ? "":params.get("page").toString()),
                Integer.parseInt(params.get("limit").toString()));
        String ownerId = params.get("ownerId")==null ? "":params.get("ownerId").toString();
        return paymentRecordService.indexPage(page,ownerId);
    }

    /**
     * 添加
     * @param  paymentRecord  实体
     * @return success/false
     */
    @PostMapping
    public R<Boolean> add(@RequestBody PaymentRecord paymentRecord) {
        return new R<>(paymentRecordService.insert(paymentRecord));
    }

    /**
     * 删除
     * @param id ID
     * @return success/false
     */
    @DeleteMapping("/{id}")
    public R<Boolean> delete(@PathVariable String id) {
        PaymentRecord paymentRecord = new PaymentRecord();
        paymentRecord.setId(id);
        paymentRecord.setDelFlag(CommonConstant.STATUS_DEL);
        return new R<>(paymentRecordService.updateById(paymentRecord));
    }

    /**
     * 编辑
     * @param  paymentRecord  实体
     * @return success/false
     */
    @PutMapping
    public R<Boolean> edit(@RequestBody PaymentRecord paymentRecord) {
        return new R<>(paymentRecordService.updateById(paymentRecord));
    }
}
